package sharm.dao.impl;

import sharm.dao.CommentDao;
import sharm.pojo.Book;
import sharm.pojo.Comment;

import java.util.List;

/*
 * @author ViTe
 * @create 2022/6/4 - 19:02
 */
public class CommentDaoImpl extends BaseDao implements CommentDao {
    @Override
    public int addComment(Comment comment) {

        String sql = "insert into t_comment(`name`,`content`,`gamename`,`id`) values(?,?,?,?)";
        return update(sql, comment.getName(), comment.getContent(), comment.getGamename(), comment.getId());
    }

    @Override
    public int deleteCommentByid(Integer id) {
        String sql = "delete from t_comment where id = ?";
        return update(sql, id);
    }

    @Override
    public List<Comment> queryComments(String gamename) {
        String sql = "select * from t_comment where gamename = ?";
        return queryForList(Comment.class, sql, gamename);
    }

    @Override
    public Integer queryForPageTotalCount(String gamename) {
        String sql = "select count(*) from t_comment where gamename = ?";
        Number count = (Number) queryForSingleValue(sql, gamename);
        return count.intValue();
    }

    @Override
    public List<Comment> queryForPageItems(int begin, int pageSize, String gamename) {
        String sql = "select `name` , `content` , `gamename` , `id` from t_comment where gamename = ? limit ?,?";
        return queryForList(Comment.class,sql, gamename, begin,pageSize);
    }
}
